/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.zcm.modules.xgb.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.zcm.common.config.Global;
import com.zcm.common.persistence.Page;
import com.zcm.common.web.BaseController;
import com.zcm.common.utils.StringUtils;
import com.zcm.modules.xgb.entity.XgbBoardStock;
import com.zcm.modules.xgb.service.XgbBoardStockService;

/**
 * XgbBoardStockController
 * @author www
 * @version 2018-10-07
 */
@Controller
@RequestMapping(value = "${adminPath}/xgb/xgbBoardStock")
public class XgbBoardStockController extends BaseController {

	@Autowired
	private XgbBoardStockService xgbBoardStockService;
	
	@ModelAttribute
	public XgbBoardStock get(@RequestParam(required=false) String id) {
		XgbBoardStock entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = xgbBoardStockService.get(id);
		}
		if (entity == null){
			entity = new XgbBoardStock();
		}
		return entity;
	}
	
	@RequiresPermissions("xgb:xgbBoardStock:view")
	@RequestMapping(value = {"list", ""})
	public String list(XgbBoardStock xgbBoardStock, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<XgbBoardStock> page = xgbBoardStockService.findPage(new Page<XgbBoardStock>(request, response), xgbBoardStock); 
		model.addAttribute("page", page);
		return "modules/xgb/xgbBoardStockList";
	}

	@RequiresPermissions("xgb:xgbBoardStock:view")
	@RequestMapping(value = "form")
	public String form(XgbBoardStock xgbBoardStock, Model model) {
		model.addAttribute("xgbBoardStock", xgbBoardStock);
		return "modules/xgb/xgbBoardStockForm";
	}

	@RequiresPermissions("xgb:xgbBoardStock:edit")
	@RequestMapping(value = "save")
	public String save(XgbBoardStock xgbBoardStock, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, xgbBoardStock)){
			return form(xgbBoardStock, model);
		}
		xgbBoardStockService.save(xgbBoardStock);
		addMessage(redirectAttributes, "保存XgbBoardStock成功");
		return "redirect:"+Global.getAdminPath()+"/xgb/xgbBoardStock/?repage";
	}
	
	@RequiresPermissions("xgb:xgbBoardStock:edit")
	@RequestMapping(value = "delete")
	public String delete(XgbBoardStock xgbBoardStock, RedirectAttributes redirectAttributes) {
		xgbBoardStockService.delete(xgbBoardStock);
		addMessage(redirectAttributes, "删除XgbBoardStock成功");
		return "redirect:"+Global.getAdminPath()+"/xgb/xgbBoardStock/?repage";
	}

}